
package hopital.admin;

import hopital.orm.Chambre;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

public class ChambreInterface extends javax.swing.JInternalFrame {

    public ChambreInterface() {
        initComponents();
        initiallize();
        
    }
    public final void initiallize()
    {
        try {
            List<Object> _list = hopital.sql.SqlDatabase.getDatabase().retrive(new Chambre());
            list1.removeItems();
            for(Object _doc:_list){
                list1.addItem(_doc);
            }
        } catch (Exception ex) {
            Logger.getLogger(ChambreInterface.class.getName()).log(Level.SEVERE, null, ex);
        }
    } 
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jSplitPane1 = new javax.swing.JSplitPane();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        list1 = new hopital.ui.List();
        _panel = new javax.swing.JPanel();
        jToolBar1 = new javax.swing.JToolBar();
        _add = new javax.swing.JButton();
        _modify = new javax.swing.JButton();
        _delete = new javax.swing.JButton();
        _delete1 = new javax.swing.JButton();

        setFrameIcon(null);

        jPanel2.setLayout(new java.awt.BorderLayout());

        list1.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                list1ValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(list1);

        jPanel2.add(jScrollPane1, java.awt.BorderLayout.CENTER);

        jSplitPane1.setLeftComponent(jPanel2);

        javax.swing.GroupLayout _panelLayout = new javax.swing.GroupLayout(_panel);
        _panel.setLayout(_panelLayout);
        _panelLayout.setHorizontalGroup(
            _panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 479, Short.MAX_VALUE)
        );
        _panelLayout.setVerticalGroup(
            _panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 347, Short.MAX_VALUE)
        );

        jSplitPane1.setRightComponent(_panel);

        getContentPane().add(jSplitPane1, java.awt.BorderLayout.CENTER);

        jToolBar1.setFloatable(false);
        jToolBar1.setRollover(true);

        _add.setIcon(new javax.swing.ImageIcon(getClass().getResource("/hopital/icon/plus25.png"))); // NOI18N
        _add.setText("Nouveau");
        _add.setFocusable(false);
        _add.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        _add.setMaximumSize(new java.awt.Dimension(100, 100));
        _add.setMinimumSize(new java.awt.Dimension(100, 100));
        _add.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        _add.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _addActionPerformed(evt);
            }
        });
        jToolBar1.add(_add);

        _modify.setIcon(new javax.swing.ImageIcon(getClass().getResource("/hopital/icon/font2.png"))); // NOI18N
        _modify.setText("Editer");
        _modify.setFocusable(false);
        _modify.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        _modify.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        _modify.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _modifyActionPerformed(evt);
            }
        });
        jToolBar1.add(_modify);

        _delete.setIcon(new javax.swing.ImageIcon(getClass().getResource("/hopital/icon/remove11.png"))); // NOI18N
        _delete.setText("Supprimer");
        _delete.setFocusable(false);
        _delete.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        _delete.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        _delete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _deleteActionPerformed(evt);
            }
        });
        jToolBar1.add(_delete);

        _delete1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/hopital/icon/nine10.png"))); // NOI18N
        _delete1.setText("Bloc");
        _delete1.setFocusable(false);
        _delete1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        _delete1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        _delete1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _delete1ActionPerformed(evt);
            }
        });
        jToolBar1.add(_delete1);

        getContentPane().add(jToolBar1, java.awt.BorderLayout.PAGE_START);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void list1ValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_list1ValueChanged
        if (list1.getSelectedValue()!=null) {
            
        }
    }//GEN-LAST:event_list1ValueChanged

    private void _addActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__addActionPerformed
        try {
            ChambreDialog cd=new ChambreDialog(null, new Chambre());
            initiallize();
        } catch (Exception e) {
        }
            
    }//GEN-LAST:event__addActionPerformed

    private void _modifyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__modifyActionPerformed
       if (list1.getSelectedValue()!=null) {
           try{
               Chambre _chbr=(Chambre) list1.getSelectedValue();
               ChambreDialog cd=new ChambreDialog(null, _chbr);
               initiallize();
           } catch (Exception ex) {
               Logger.getLogger(ChambreInterface.class.getName()).log(Level.SEVERE, null, ex);
           }
        }
    }//GEN-LAST:event__modifyActionPerformed

    private void _deleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__deleteActionPerformed
        if (list1.getSelectedValue()!=null) {
           try {
               Chambre _chbr=(Chambre) list1.getSelectedValue();
               hopital.sql.SqlDatabase.getDatabase().destroy(_chbr);
               initiallize();
           } catch (Exception ex) {
               Logger.getLogger(ChambreInterface.class.getName()).log(Level.SEVERE, null, ex);
           }
        }
    }//GEN-LAST:event__deleteActionPerformed

    private void _delete1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__delete1ActionPerformed
        try {
            BlocDialog blocDialog = new BlocDialog(null);
        } catch (Exception e) {
        }
        
    }//GEN-LAST:event__delete1ActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton _add;
    private javax.swing.JButton _delete;
    private javax.swing.JButton _delete1;
    private javax.swing.JButton _modify;
    protected javax.swing.JPanel _panel;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JToolBar jToolBar1;
    private hopital.ui.List list1;
    // End of variables declaration//GEN-END:variables
}
